﻿using System;
using System.Xml.Serialization;
using System.IO;
using System.Collections.Generic;

namespace BizControl.Library.AI
{
  public class ModelBase<T> : IModel<T>
  {
    #region IModel<T> Members

    public virtual IProcess<T> GenerateModel(IEnumerable<T> data)
    {
      throw new NotImplementedException();
    }

    public virtual IProcess<T> Load(string filename)
    {
      using (var fileStream = File.OpenRead(filename))
      {
        return Load(fileStream); ;
      }
    }

    public virtual IProcess<T> Load(Stream stream)
    {
      ProcessorBase<T> processor = new ProcessorBase<T>();
      XmlSerializer serializer = new XmlSerializer(processor.GetType());
      return (ProcessorBase<T>)serializer.Deserialize(stream);
    }

    #endregion
  }
}
